package crossrun.tool.pdf2img.livedata;

import android.content.Context;
import android.net.Uri;

import androidx.lifecycle.LiveData;

import java.io.File;

import crossrun.tool.pdf2img.util.FileUtils;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.schedulers.Schedulers;

public class PdfFileReadData extends LiveData<File> {
    public static void  getPdfFileFromUri(final Context context,final Uri uri, Observer<File> observer){
        Observable
                .create(new ObservableOnSubscribe<File>() {
                    @Override
                    public void subscribe(@NonNull ObservableEmitter<File> emitter) throws Throwable {
                        File pdfFile=FileUtils.getFilePathByUri(context,uri);
                        emitter.onNext(pdfFile);
                    }
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
